Inside Macintosh: Macintosh Toolbox Essentials

Previous | Chapter Top | Chapter Contents | Next

Getting Timing Information

You can get the current number of ticks since the system last started up using the TickCount function (TickCount) . You can use this function to compare the number of ticks that have expired since a given event or other action occurred.

By using the GetDblTime function (GetDblTime) , you can get the suggested maximum difference in ticks that should exist to consider two mouse events a double click. The user can adjust this value using the Mouse control panel. Using the GetCaretTime function (GetCaretTime) , you can get the suggested maximum difference in ticks that should exist between blinks of the caret in editable text. The user can adjust this value using the General Controls panel.

TickCount

You can use the TickCount function to get the current number of ticks (a tick is approximately 1/60 of a second) since the system last started up.

pascal UInt32 TickCount (void);

DESCRIPTION

The TickCount function returns an unsigned 32-bit integer that indicates the current number of ticks since the system last started up. You can use this value to compare the number of ticks that have elapsed since a given event or other action occurred. For example, you could compare the current value returned by TickCount with the value of the when field of an event record.

The tick count is incremented during the vertical retrace interrupt, but this interrupt can be disabled. Your application should not rely on the tick count to increment with absolute precision. Your application also should not assume that the tick count always increments by 1; an interrupt task might keep control for more than one tick. If your application keeps track of the previous tick count and then compares this value with the current tick count, your application should compare the two values by checking for a "greater than or equal" condition rather than "equal to previous tick count plus 1."

Don't rely on the tick count being exact; it's usually accurate to within one tick, but this level of accuracy is not guaranteed.

ASSEMBLY-LANGUAGE NOTE

The value returned by TickCount is also accessible in the global variable Ticks .

GetDblTime

To determine whether a sequence of mouse events constitutes a double click, your application measures the elapsed time (in ticks) between a mouse-up event and a mouse-down event. If the time between the two mouse events is less than the value returned by GetDblTime , your application should interpret the two mouse events as a double click.

pascal UInt32 GetDblTime (void)

DESCRIPTION

The GetDblTime function returns the suggested maximum elapsed time, in ticks, between a mouse-up event and a mouse-down event. The user can adjust this value using the Mouse control panel.

If your application distinguishes a double click of the mouse from a single click, your application should use the value returned by GetDblTime to make this distinction. If your application uses TextEdit, the TextEdit functions automatically recognize and handle double clicks of text within a TextEdit edit record by appropriately highlighting or unhighlighting the selection.

The ratio of ticks to value in the DoubleTime global variable is 1:1. However, the Finder multiplies DoubleTime by 2 to determine double click time because it needs to account for user problems that typically occur during icon arrangement. Therefore, the Finder uses DoubleTime*2 whereas the rest of the system uses DoubleTime .

Incidentally, the Finder does not limit the DoubleTime to 64 ticks. In most places, it treats it like a byte although in some others it treats it like a longword. The best method would be to provide a one-second double-byte (two seconds in the Finder).

ASSEMBLY-LANGUAGE NOTE

The value returned b y GetDblTime is also accessible in the system global variable DoubleTime .

LMSetDoubleTime

Sets the elapsed time (in ticks) between a mouse-up event and a mouse-down event.

pascal void LMSetDoubleTime (UInt32 value);
value
An unsigned 32-bit integer that specifies the suggested maximum elapsed time, in ticks, between a mouse-up event and a mouse-down event. The user can adjust this value using the Mouse control panel.

DESCRIPTION

The LMSetDblTime function sets the suggested maximum elapsed time, in ticks, between a mouse-up event and a mouse-down event. The user can adjust this value using the Mouse control panel.

If your application distinguishes a double click of the mouse from a single click, your application should use the value set by LMSetDblTime to make this distinction. If your application uses TextEdit, the TextEdit functions automatically recognize and handle double clicks of text within a TextEdit edit record by appropriately highlighting or unhighlighting the selection.

ASSEMBLY-LANGUAGE NOTE

The value set b y LMSetDblTime is also accessible in the system global variable DoubleTime .

GetCaretTime

You can use the GetCaretTime function to get the suggested difference in ticks that should exist between blinks of the caret (usually a vertical bar marking the insertion point) in editable text. The user can adjust this value using the General Controls panel.

pascal UInt32 GetCaretTime (void)

DESCRIPTION

If your application supports editable text, your application should use the value returned by GetCaretTime to determine how often to blink the caret. If your application uses only TextEdit, you can use TextEdit functions to automatically blink the caret at the time interval that the user specifies in the General Controls panel.

ASSEMBLY-LANGUAGE NOTE

The value returned by GetCaretTime is also accessible in the system global variable CaretTime .

LMSetCaretTime

Sets the suggested difference in ticks that should exist between blinks of the caret (usually a vertical bar marking the insertion point) in editable text. The user can adjust this value using the General Controls panel.

pascal void LMSetCaretTime (UInt32 value);
value
An unsigned 32-bit value that specifies the difference in ticks that should exist between blinks of the caret

DESCRIPTION

If your application supports editable text, your application should use the value returned by LMSetCaretTime to determine how often to blink the caret.

ASSEMBLY-LANGUAGE NOTE

The value set by LMSetCaretTime is also accessible in the system global variable CaretTime .


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next